package com.ruoyi.orderview.service.impl;

import com.ruoyi.orderview.service.ReturnThing;
import com.ruoyi.orderview.domain.ReturnNum;
import com.ruoyi.orderview.mapper.ReturnNumMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.orderview.utils.DateGrouping;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Author 程家伟
 * Date 2022/1/22 10:33
 * Email 3497357686@qq.com
 */

@Service
public class ReturnThingImpl implements ReturnThing {

    @Autowired
    private ReturnNumMapper returnNumMapper;

    /**
     * 返回日期列表
     * @return
     */
    @Override
    public List<String> getDateList(Date start, Date end) {
        return new DateGrouping().getTimeList(start, end);
    }

    /**
     * 返回日期之间的订单数量列表
     * @return
     */
    @Override
    public List<Integer> getNumList(Date start,Date end,int type) {
        List<String> dates = new DateGrouping().getTimeList(start, end);
        ArrayList<Integer> integers = new ArrayList<>();
        for (int i = 0; i < dates.size()-1; i++) {

            if (type==1) {
                Integer first=returnNumMapper.getInPracticeNum(dates.get(i),dates.get(i+1));
                if (null != first){
                    integers.add(first);
                }else {
                    integers.add(0);
                }

            }else  if (type==2) {
                Integer first=returnNumMapper.getOutPracticeNum(dates.get(i),dates.get(i+1));
                if (null != first){
                    integers.add(first);
                }else {
                    integers.add(0);
                }

            }else             if (type==3) {
                Integer first=returnNumMapper.getInGraftingNum(dates.get(i),dates.get(i+1));
                if (null != first){
                    integers.add(first);
                }else {
                    integers.add(0);
                }

            }else       if (type==4) {
                Integer first=returnNumMapper.getOutGraftingNum(dates.get(i),dates.get(i+1));
                if (null != first){
                    integers.add(first);
                }else {
                    integers.add(0);
                }

            }
        }
        return integers;
    }

    /**
     * 返回ReturnNum列表
     * @return
     */
    @Override
    public List<ReturnNum> getReturnNumList(List<String> dates, List<Integer> nums) {
        ArrayList<ReturnNum> returnNums = new ArrayList<>();
        for (int i = 0; i < nums.size(); i++) {
            returnNums.add(new ReturnNum(dates.get(i),nums.get(i)));
        }
        return returnNums;
    }

    /**
     * 返回总的个数
     * @param start
     * @param end
     * @return
     */
    @Override
    public Integer getTotal(Date start, Date end) {
        DateGrouping dateGrouping = new DateGrouping();
        long intervalTime = dateGrouping.judgeTime(start, end);
        return dateGrouping.judgeTotal(intervalTime);
    }

}
